﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using ScrumFactory.Composition.ViewModel;
using ScrumFactory.Composition;
using ScrumFactory.ProjectSummary;

namespace ScrumFactory.ProjectSummary.Tests
{

    [TestClass()]
    public class ProjectDetailsViewModelTest
    {
        [TestMethod()]
        public void ProjectDetailsViewModelUpdatesViewOnViewProjectDetailsEvent()
        {
            var aggregator = new Mock<IEventAggregator>();
            var project = new Project();

            // The mock event aggregator will fire the event "ViewProjectDetails", passing the project variable, as soon as the ViewModel subscribes to it
            aggregator.Setup(a => a.Subscribe<Project>(ScrumFactoryEvent.ViewProjectDetails, It.IsAny<Action<Project>>())).Callback<string, Action<Project>>((e, del) =>
            {
                del(project); // Call the subscribed delegate
            }).Verifiable("<Project> \"ViewProjectDetails\" event was not subscribed");


            var view = new Mock<IProjectSummaryView>();

            var target = new ViewModel.ProjectSummaryViewModel(aggregator.Object, null, null, null, null);

            aggregator.Verify();

            Assert.AreSame(project, target.Project, "Project property was not set in model.");
        }
    }
}
